using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace EOSDigital.SDK
{
	public static class CanonSDK
	{
		public const int MAX_NAME = 256;

		public const int TRANSFER_BLOCK_SIZE = 512;

		public const string DllPath = "EDSDK/EDSDK.DLL";

		public static Version SDKVersion
		{
			get;
			private set;
		}

		public static bool IsVerGE34
		{
			get;
			private set;
		}

		public static void InitializeVersion()
		{
			try
			{
				CanonSDK.SDKVersion = CanonSDK.GetSDKVersion();
				if (CanonSDK.SDKVersion == (Version)null)
				{
					throw new InvalidOperationException("Could not find SDK version");
				}
				CanonSDK.IsVerGE34 = (CanonSDK.SDKVersion.Major >= 3 && CanonSDK.SDKVersion.Minor >= 4);
			}
			catch (Exception innerException)
			{
				throw new InvalidOperationException("Could not find SDK version", innerException);
			}
		}

		private static Version GetSDKVersion()
		{
			ProcessModuleCollection modules = Process.GetCurrentProcess().Modules;
			foreach (object item in modules)
			{
				ProcessModule processModule = item as ProcessModule;
				if (processModule != null)
				{
					string a = processModule.ModuleName.ToLower();
					if (a == "edsdk.dll")
					{
						FileVersionInfo fileVersionInfo = processModule.FileVersionInfo;
						return new Version(fileVersionInfo.ProductMajorPart, fileVersionInfo.ProductMinorPart, fileVersionInfo.ProductBuildPart, fileVersionInfo.ProductPrivatePart);
					}
				}
			}
			return null;
		}

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsInitializeSDK();

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsTerminateSDK();

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsOpenSession(IntPtr inCameraRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCloseSession(IntPtr inCameraRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetPropertySize(IntPtr inRef, PropertyID inPropertyID, int inParam, out DataType outDataType, out int outSize);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, int inPropertySize, IntPtr outPropertyData);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, int inPropertySize, [In] [MarshalAs(UnmanagedType.AsAny)] object inPropertyData);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetPropertyDesc(IntPtr inRef, PropertyID inPropertyID, out PropertyDesc outPropertyDesc);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSendCommand(IntPtr inCameraRef, CameraCommand inCommand, int inParam);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSendStatusCommand(IntPtr inCameraRef, CameraStatusCommand inCameraState, int inParam);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSetCapacity(IntPtr inCameraRef, Capacity inCapacity);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetVolumeInfo(IntPtr inCameraRef, out VolumeInfo outVolumeInfo);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsFormatVolume(IntPtr inVolumeRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetDirectoryItemInfo(IntPtr inDirItemRef, out DirectoryItemInfo outDirItemInfo);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsDeleteDirectoryItem(IntPtr inDirItemRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetAttribute(IntPtr inDirItemRef, out FileAttribute outFileAttribute);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSetAttribute(IntPtr inDirItemRef, FileAttribute inFileAttribute);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsDownload(IntPtr inDirItemRef, int inReadSize, IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsDownload(IntPtr inDirItemRef, long inReadSize, IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsDownloadCancel(IntPtr inDirItemRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsDownloadComplete(IntPtr inDirItemRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsDownloadThumbnail(IntPtr inDirItemRef, IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCreateFileStream(string inFileName, FileCreateDisposition inCreateDisposition, FileAccess inDesiredAccess, out IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCreateMemoryStream(int inBufferSize, out IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCreateMemoryStream(long inBufferSize, out IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL", CharSet = CharSet.Unicode)]
		public static extern ErrorCode EdsCreateFileStreamEx(string inFileName, FileCreateDisposition inCreateDisposition, FileAccess inDesiredAccess, out IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCreateMemoryStreamFromPointer(IntPtr inUserBuffer, int inBufferSize, out IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCreateMemoryStreamFromPointer(IntPtr inUserBuffer, long inBufferSize, out IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCreateMemoryStreamFromPointer(byte[] inUserBuffer, int inBufferSize, out IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCreateMemoryStreamFromPointer(byte[] inUserBuffer, long inBufferSize, out IntPtr outStream);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCreateStream(IntPtr inStream, IntPtr outStreamRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetPointer(IntPtr inStreamRef, out IntPtr outPointer);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsRead(IntPtr inStreamRef, int inReadSize, IntPtr outBuffer, out int outReadSize);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsRead(IntPtr inStreamRef, long inReadSize, IntPtr outBuffer, out long outReadSize);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsWrite(IntPtr inStreamRef, int inWriteSize, IntPtr inBuffer, out int outWrittenSize);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsWrite(IntPtr inStreamRef, long inWriteSize, IntPtr inBuffer, out long outWrittenSize);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSeek(IntPtr inStreamRef, int inSeekOffset, SeekOrigin inSeekOrigin);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSeek(IntPtr inStreamRef, long inSeekOffset, SeekOrigin inSeekOrigin);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetPosition(IntPtr inStreamRef, out int outPosition);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetPosition(IntPtr inStreamRef, out long outPosition);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetLength(IntPtr inStreamRef, out int outLength);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetLength(IntPtr inStreamRef, out long outLength);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCopyData(IntPtr inStreamRef, int inWriteSize, IntPtr outStreamRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCopyData(IntPtr inStreamRef, long inWriteSize, IntPtr outStreamRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCreateImageRef(IntPtr inStreamRef, out IntPtr outImageRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetImageInfo(IntPtr inImageRef, ImageSource inImageSource, out ImageInfo outImageInfo);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetImage(IntPtr inImageRef, ImageSource inImageSource, TargetImageType inImageType, Rectangle inSrcRect, Size inDstSize, IntPtr outStreamRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSaveImage(IntPtr inImageRef, SaveImageType inImageType, SaveImageSetting inSaveSetting, IntPtr outStreamRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCacheImage(IntPtr inImageRef, bool inUseCache);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsReflectImageProperty(IntPtr inImageRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSetCameraAddedHandler(SDKCameraAddedHandler inCameraAddedHandler, IntPtr inContext);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSetPropertyEventHandler(IntPtr inCameraRef, PropertyEventID inEvent, SDKPropertyEventHandler inPropertyEventHandler, IntPtr inContext);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSetObjectEventHandler(IntPtr inCameraRef, ObjectEventID inEvent, SDKObjectEventHandler inObjectEventHandler, IntPtr inContext);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSetCameraStateEventHandler(IntPtr inCameraRef, StateEventID inEvent, SDKStateEventHandler inStateEventHandler, IntPtr inContext);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsSetProgressCallback(IntPtr inRef, SDKProgressCallback inProgressFunc, ProgressOption inProgressOption, IntPtr inContext);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetEvent();

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsCreateEvfImageRef(IntPtr inStreamRef, out IntPtr outEvfImageRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsDownloadEvfImage(IntPtr inCameraRef, IntPtr outEvfImageRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetCameraList(out IntPtr outCameraListRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetDeviceInfo(IntPtr inCameraRef, out DeviceInfo outDeviceInfo);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern int EdsRetain(IntPtr inRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern int EdsRelease(IntPtr inRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetChildCount(IntPtr inRef, out int outCount);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetChildAtIndex(IntPtr inRef, int inIndex, out IntPtr outRef);

		[DllImport("EDSDK/EDSDK.DLL")]
		public static extern ErrorCode EdsGetParent(IntPtr inRef, out IntPtr outParentRef);

		public static ErrorCode GetDirectoryItemInfo(IntPtr inDirItemRef, out DirectoryItemInfo outDirItemInfo)
		{
			if (CanonSDK.IsVerGE34)
			{
				return CanonSDK.EdsGetDirectoryItemInfo(inDirItemRef, out outDirItemInfo);
			}
			DirectoryItemInfo_3_4 directoryItemInfo_3_ = default(DirectoryItemInfo_3_4);
			ErrorCode errorCode = CanonSDK.EdsGetDirectoryItemInfo(inDirItemRef, out directoryItemInfo_3_);
			if (errorCode == ErrorCode.OK)
			{
				outDirItemInfo = directoryItemInfo_3_.ToCurrent();
				return errorCode;
			}
			outDirItemInfo = default(DirectoryItemInfo);
			return errorCode;
		}

		[DllImport("EDSDK/EDSDK.DLL")]
		private static extern ErrorCode EdsGetDirectoryItemInfo(IntPtr inDirItemRef, out DirectoryItemInfo_3_4 outDirItemInfo);

		public static ErrorCode GetPropertyData<T>(IntPtr inRef, PropertyID inPropertyID, int inParam, out T outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			outPropertyData = default(T);
			if (((object)outPropertyData) is PictureStyleDesc)
			{
				PictureStyleDesc pictureStyleDesc = default(PictureStyleDesc);
				errorCode = CanonSDK.GetPropertyData(inRef, inPropertyID, inParam, out pictureStyleDesc);
				if (errorCode == ErrorCode.OK)
				{
					outPropertyData = (T)(object)pictureStyleDesc;
				}
			}
			else
			{
				errorCode = CanonSDK.GetPropertyDataSub<T>(inRef, inPropertyID, inParam, out outPropertyData);
			}
			return errorCode;
		}

		private static ErrorCode GetPropertyDataSub<T>(IntPtr inRef, PropertyID inPropertyID, int inParam, out T outPropertyData)
		{
			IntPtr intPtr = IntPtr.Zero;
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			outPropertyData = default(T);
			try
			{
				DataType dataType = default(DataType);
				int num = default(int);
				errorCode = CanonSDK.EdsGetPropertySize(inRef, inPropertyID, inParam, out dataType, out num);
				if (errorCode == ErrorCode.OK)
				{
					intPtr = Marshal.AllocHGlobal(num);
					errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, num, intPtr);
					if (errorCode == ErrorCode.OK)
					{
						outPropertyData = (T)Marshal.PtrToStructure(intPtr, typeof(T));
						return errorCode;
					}
					return errorCode;
				}
				return errorCode;
			}
			finally
			{
				if (intPtr != IntPtr.Zero)
				{
					Marshal.FreeHGlobal(intPtr);
				}
			}
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out bool outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(bool));
			bool flag = default(bool);
			bool* value = &flag;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = flag;
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out byte outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(byte));
			byte b = default(byte);
			byte* value = &b;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = b;
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out short outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(short));
			short num = default(short);
			short* value = &num;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = num;
			return errorCode;
		}

		[CLSCompliant(false)]
		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out ushort outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(ushort));
			ushort num = default(ushort);
			ushort* value = &num;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = num;
			return errorCode;
		}

		[CLSCompliant(false)]
		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out uint outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(uint));
			uint num = default(uint);
			uint* value = &num;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = num;
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out int outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(int));
			int num = default(int);
			int* value = &num;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = num;
			return errorCode;
		}

		public static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out string outPropertyData)
		{
			IntPtr intPtr = IntPtr.Zero;
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			outPropertyData = string.Empty;
			try
			{
				DataType dataType = default(DataType);
				int num = default(int);
				errorCode = CanonSDK.EdsGetPropertySize(inRef, inPropertyID, inParam, out dataType, out num);
				if (errorCode == ErrorCode.OK)
				{
					intPtr = Marshal.AllocHGlobal(num);
					errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, num, intPtr);
					if (errorCode == ErrorCode.OK)
					{
						outPropertyData = Marshal.PtrToStringAnsi(intPtr);
						return errorCode;
					}
					return errorCode;
				}
				return errorCode;
			}
			finally
			{
				if (intPtr != IntPtr.Zero)
				{
					Marshal.FreeHGlobal(intPtr);
				}
			}
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out bool[] outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int num = Marshal.SizeOf(typeof(bool));
			DataType dataType = default(DataType);
			int num2 = default(int);
			errorCode = CanonSDK.EdsGetPropertySize(inRef, inPropertyID, inParam, out dataType, out num2);
			if (errorCode == ErrorCode.OK)
			{
				bool[] array = new bool[num2 / num];
				bool[] array2 = array;
				fixed (bool* value = array2)
				{
					errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, num2, (IntPtr)(void*)value);
				}
				if (errorCode == ErrorCode.OK)
				{
					outPropertyData = array;
				}
				else
				{
					outPropertyData = new bool[0];
				}
			}
			else
			{
				outPropertyData = new bool[0];
			}
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out short[] outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int num = Marshal.SizeOf(typeof(short));
			DataType dataType = default(DataType);
			int num2 = default(int);
			errorCode = CanonSDK.EdsGetPropertySize(inRef, inPropertyID, inParam, out dataType, out num2);
			if (errorCode == ErrorCode.OK)
			{
				short[] array = new short[num2 / num];
				short[] array2 = array;
				fixed (short* value = array2)
				{
					errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, num2, (IntPtr)(void*)value);
				}
				if (errorCode == ErrorCode.OK)
				{
					outPropertyData = array;
				}
				else
				{
					outPropertyData = new short[0];
				}
			}
			else
			{
				outPropertyData = new short[0];
			}
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out int[] outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int num = Marshal.SizeOf(typeof(int));
			DataType dataType = default(DataType);
			int num2 = default(int);
			errorCode = CanonSDK.EdsGetPropertySize(inRef, inPropertyID, inParam, out dataType, out num2);
			if (errorCode == ErrorCode.OK)
			{
				int[] array = new int[num2 / num];
				int[] array2 = array;
				fixed (int* value = array2)
				{
					errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, num2, (IntPtr)(void*)value);
				}
				if (errorCode == ErrorCode.OK)
				{
					outPropertyData = array;
				}
				else
				{
					outPropertyData = new int[0];
				}
			}
			else
			{
				outPropertyData = new int[0];
			}
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out byte[] outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int num = Marshal.SizeOf(typeof(byte));
			DataType dataType = default(DataType);
			int num2 = default(int);
			errorCode = CanonSDK.EdsGetPropertySize(inRef, inPropertyID, inParam, out dataType, out num2);
			if (errorCode == ErrorCode.OK)
			{
				byte[] array = new byte[num2 / num];
				byte[] array2 = array;
				fixed (byte* value = array2)
				{
					errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, num2, (IntPtr)(void*)value);
				}
				if (errorCode == ErrorCode.OK)
				{
					outPropertyData = array;
				}
				else
				{
					outPropertyData = new byte[0];
				}
			}
			else
			{
				outPropertyData = new byte[0];
			}
			return errorCode;
		}

		[CLSCompliant(false)]
		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out uint[] outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int num = Marshal.SizeOf(typeof(uint));
			DataType dataType = default(DataType);
			int num2 = default(int);
			errorCode = CanonSDK.EdsGetPropertySize(inRef, inPropertyID, inParam, out dataType, out num2);
			if (errorCode == ErrorCode.OK)
			{
				uint[] array = new uint[num2 / num];
				uint[] array2 = array;
				fixed (uint* value = array2)
				{
					errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, num2, (IntPtr)(void*)value);
				}
				if (errorCode == ErrorCode.OK)
				{
					outPropertyData = array;
				}
				else
				{
					outPropertyData = new uint[0];
				}
			}
			else
			{
				outPropertyData = new uint[0];
			}
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out Rational[] outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int num = Marshal.SizeOf(typeof(Rational));
			DataType dataType = default(DataType);
			int num2 = default(int);
			errorCode = CanonSDK.EdsGetPropertySize(inRef, inPropertyID, inParam, out dataType, out num2);
			if (errorCode == ErrorCode.OK)
			{
				Rational[] array = new Rational[num2 / num];
				Rational[] array2 = array;
				fixed (Rational* value = array2)
				{
					errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, num2, (IntPtr)(void*)value);
				}
				if (errorCode == ErrorCode.OK)
				{
					outPropertyData = array;
				}
				else
				{
					outPropertyData = new Rational[0];
				}
			}
			else
			{
				outPropertyData = new Rational[0];
			}
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out Time outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(Time));
			Time time = default(Time);
			Time* value = &time;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = time;
			return errorCode;
		}

		public static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out FocusInfo outPropertyData)
		{
			IntPtr intPtr = IntPtr.Zero;
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			try
			{
				int num = Marshal.SizeOf(typeof(FocusInfo));
				intPtr = Marshal.AllocHGlobal(num);
				errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, num, intPtr);
				outPropertyData = (FocusInfo)Marshal.PtrToStructure(intPtr, typeof(FocusInfo));
				return errorCode;
			}
			finally
			{
				if (intPtr != IntPtr.Zero)
				{
					Marshal.FreeHGlobal(intPtr);
				}
			}
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out FocusPoint outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(FocusPoint));
			FocusPoint focusPoint = default(FocusPoint);
			FocusPoint* value = &focusPoint;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = focusPoint;
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out Size outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(Size));
			Size size = default(Size);
			Size* value = &size;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = size;
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out Rectangle outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(Rectangle));
			Rectangle rectangle = default(Rectangle);
			Rectangle* value = &rectangle;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = rectangle;
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out Point outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(Point));
			Point point = default(Point);
			Point* value = &point;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = point;
			return errorCode;
		}

		public unsafe static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out MyMenuItems outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			int inPropertySize = Marshal.SizeOf(typeof(MyMenuItems));
			MyMenuItems myMenuItems = default(MyMenuItems);
			MyMenuItems* value = &myMenuItems;
			errorCode = CanonSDK.EdsGetPropertyData(inRef, inPropertyID, inParam, inPropertySize, (IntPtr)(void*)value);
			outPropertyData = myMenuItems;
			return errorCode;
		}

		public static ErrorCode GetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, out PictureStyleDesc outPropertyData)
		{
			ErrorCode errorCode = ErrorCode.INTERNAL_ERROR;
			outPropertyData = default(PictureStyleDesc);
			DataType dataType = default(DataType);
			int num = default(int);
			errorCode = CanonSDK.EdsGetPropertySize(inRef, inPropertyID, inParam, out dataType, out num);
			if (errorCode == ErrorCode.OK)
			{
				if (num == Marshal.SizeOf(typeof(PictureStyleDesc)))
				{
					return CanonSDK.GetPropertyDataSub<PictureStyleDesc>(inRef, inPropertyID, inParam, out outPropertyData);
				}
				if (num == Marshal.SizeOf(typeof(PictureStyleDesc_3_2)))
				{
					PictureStyleDesc_3_2 pictureStyleDesc_3_ = default(PictureStyleDesc_3_2);
					errorCode = CanonSDK.GetPropertyDataSub<PictureStyleDesc_3_2>(inRef, inPropertyID, inParam, out pictureStyleDesc_3_);
					if (errorCode == ErrorCode.OK)
					{
						outPropertyData = pictureStyleDesc_3_.ToCurrent();
						return errorCode;
					}
					goto IL_006f;
				}
				throw new InvalidOperationException("Cannot find correct struct size");
			}
			goto IL_006f;
			IL_006f:
			return errorCode;
		}
	}
}
